// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_SALES_ORDER_ITEM
// * CreateDate    : 2011/8/16 10:16:41
// * Creater       : CodeSmith
// * LastChangeDate: 2011/8/16 10:16:41
// * LastChanger   : 2011/8/16 10:16:41
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Sales
{
/// <summary>
    /// SalesOrderItem
    /// </summary>
    public partial class SalesOrderItemBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objSalesOrderItemEntity">Entity</param>
        /// <returns>Entity</returns>
        public static SalesOrderItemEntity GetSalesOrderItem(SalesOrderItemEntity objSalesOrderItemEntity)
        {
            return DataAccess.SelectSingle<SalesOrderItemEntity>(objSalesOrderItemEntity);
        }

        public static SalesOrderItemEntity GetSalesQuoteItemByID(string itemID)
        {
            if (string.IsNullOrEmpty(itemID))
            {
                return null;
            }
            SalesOrderItemEntity entity = new SalesOrderItemEntity();
            entity.OrderItemId = itemID;
            return DataAccess.SelectSingle<SalesOrderItemEntity>(entity);
        }
        public static List<SalesOrderItemEntity> GetBySalesOrderID(string orderID)
        {
            if (string.IsNullOrEmpty(orderID))
            {
                return null;
            }
            SalesOrderItemEntity entity = new SalesOrderItemEntity();
            entity.OrderId = orderID;
            return DataAccess.Select<SalesOrderItemEntity>(entity);
        }
        public static DataSet GetDataSetByOrderID(string orderID)
        {
            if (string.IsNullOrEmpty(orderID))
            {
                return null;
            }
//            string sql = @"SELECT CONVERT(DECIMAL(18,2),SI.PRICE_NO_TAX) AS PRICE_NO_TAX, SI.*,P.*, CONVERT(DECIMAL(18,2),SI.QTY*SI.PRICE_NO_TAX) AS TOTAL_AMOUNT, 
//							C.ITEM_NAME, CONVERT(NVARCHAR(10),SO.DELIVERY_DATE,120) AS REQUIRED_DELIVERY_DATE
//                            FROM SALES_ORDER_ITEM SI
//                            INNER JOIN SALES_ORDER SO ON SO.ORDER_ID = SI.ORDER_ID
//                            LEFT JOIN MST_PRODUCT P ON P.PRODUCT_ID = SI.PRODUCT_ID
//							LEFT JOIN SALES_PROD_PLAN_APPLICATION_ITEM AI ON AI.ORDER_ITEM_ID = SI.ORDER_ITEM_ID
//							LEFT JOIN MST_COMMON_ITEM C ON C.ITEM_CODE = AI.PRODUCT_TYPE
//                            WHERE SI.ORDER_ID = '" + orderID + "'";
            string sql = @"SELECT CONVERT(DECIMAL(18,2),SI.PRICE_NO_TAX) AS PRICE_NO_TAX, SI.*,P.*, CONVERT(DECIMAL(18,2),SI.QTY*SI.PRICE_NO_TAX) AS TOTAL_AMOUNT, 
							C.ITEM_NAME, CONVERT(NVARCHAR(10),SO.DELIVERY_DATE,120) AS REQUIRED_DELIVERY_DATE,AI.APPLICATION_ITEM_ID
                            FROM SALES_ORDER_ITEM SI
                            INNER JOIN SALES_ORDER SO ON SO.ORDER_ID = SI.ORDER_ID
                            LEFT JOIN MST_PRODUCT P ON P.PRODUCT_ID = SI.PRODUCT_ID
                            LEFT JOIN dbo.SALES_ORDER_ITEM_TO_APPITEM REL ON REL.ORDER_ITEM_ID=SI.ORDER_ITEM_ID
							LEFT JOIN SALES_PROD_PLAN_APPLICATION_ITEM AI ON AI.APPLICATION_ITEM_ID = REL.APPLICATION_ITEM_ID
							LEFT JOIN MST_COMMON_ITEM C ON C.ITEM_CODE = AI.PRODUCT_TYPE
                            WHERE SI.ORDER_ID = '" + orderID + "'";

            return DataAccess.SelectDataSet(sql);
        }
        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objSalesOrderItemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertSalesOrderItem(SalesOrderItemEntity objSalesOrderItemEntity)
        {
            return DataAccess.Insert(objSalesOrderItemEntity);
        }

        public static bool InsertSalesOrderItem(List<SalesOrderItemEntity> objSalesOrderItemEntityList)
        {
            return DataAccess.Insert(objSalesOrderItemEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objSalesOrderItemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateSalesOrderItem(SalesOrderItemEntity objSalesOrderItemEntity)
        {
            return DataAccess.Update(objSalesOrderItemEntity);
        }

        public static bool UpdateSalesOrderItem(List<SalesOrderItemEntity> objSalesOrderItemEntityList)
        {
            return DataAccess.Update<SalesOrderItemEntity>(objSalesOrderItemEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objSalesOrderItemEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteSalesOrderItem(SalesOrderItemEntity objSalesOrderItemEntity)
        {
            return DataAccess.Delete(objSalesOrderItemEntity);
        }

        public static bool DeleteSalesOrderItem(List<SalesOrderItemEntity> objSalesOrderItemEntityList)
        {
            return DataAccess.Delete<SalesOrderItemEntity>(objSalesOrderItemEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetSalesOrderItemAll()
        {
            return DataAccess.SelectAllDataSet<SalesOrderItemEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<SalesOrderItemEntity> GetSalesOrderItemAllList()
        {
            return DataAccess.SelectAll<SalesOrderItemEntity>();
        }
        #endregion
	}
	
	
}	

